import {XHttpConfig, XHttpConst} from 'react-native-easy-app';
import LoadingUtil from '../common/Utils/LoadingUtil';
import { RNStorage } from '../common/Storage/AppStorage';
import { BaseURL } from './Api';

/**
 * RN Http请求 库设置类
 */
export default class HttpConfig {

    static init() {
        XHttpConfig("mqttmonitor").initLogOn(true)
            .initBaseUrl(BaseURL)
            .initHeaderSetFunc((headers, request)=>{
                //headers["authorization"] = RNStorage.accessToken;
            })
            .initContentType(XHttpConst.CONTENT_TYPE_JSON)
            .initTimeout(30000)
            .initParseDataFunc((result, request, callback) => {
                let {success, json, message, status, response} = result;
                if (status == 200 && (json && json.status === 1003)) {// token 过期
                    //Notify.TOKEN_EXPIRED.sendEvent({message})
                    callback(success, json, message, status, response);
                    LoadingUtil.dismissLoading();
                } else {
                    callback(success, json, message, status, response)
                }
            });
    }

}